package com.example.scribe;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/** Small AST node for demonstration. */
public class SyntaxNode {
    private final String type;
    private final String text;
    private final List<SyntaxNode> children = new ArrayList<>();

    public SyntaxNode(String type, String text) {
        this.type = type;
        this.text = text;
    }

    public void addChild(SyntaxNode node) {
        children.add(node);
    }

    public List<SyntaxNode> children() {
        return Collections.unmodifiableList(children);
    }

    public String type() { return type; }
    public String text() { return text; }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        toString(sb, "");
        return sb.toString();
    }

    private void toString(StringBuilder sb, String indent) {
        sb.append(indent).append(type).append(": ").append(text).append('\n');
        for (SyntaxNode c : children) c.toString(sb, indent + "  ");
    }
}
